from django.db import models

# Create your models here.
from django.contrib.auth.models import AbstractUser
from django.db import models

# Create your models here.
class Viptype(models.Model):
    vip_type=models.IntegerField(verbose_name='会员时间类型',default=30)
    price=models.IntegerField(verbose_name='价格',default=15)
    class Meta:
        db_table = 'tilitil_viptype'
        verbose_name = 'Vip类型表'
        verbose_name_plural = verbose_name




class User(AbstractUser):
    icon = models.ImageField(upload_to='icon', default='icon/default.png')
    mobile = models.CharField(max_length=11, null=True,verbose_name='手机号')
    age=models.IntegerField(null=True,verbose_name='年龄')
    gender=models.IntegerField(choices=((1, '男'), (2, '女'),(0, '隐藏')), default=0,verbose_name='性别')
    addr=models.CharField(max_length=64,default='未知')
    icon_base=models.TextField(null=True)



    class Meta:
        db_table = 'tilitil_user'
        verbose_name = '用户表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.username


class Vip(models.Model):
    create_time=models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    expiration_time=models.DateTimeField(verbose_name='过期时间')
    user=models.OneToOneField(to=User,on_delete=models.DO_NOTHING)
    class Meta:
        db_table = 'tilitil_vip'
        verbose_name = 'Vip表'
        verbose_name_plural = verbose_name



    def odd_time(self):
        import datetime
        now_time=datetime.datetime.now()
        expiration_time=self.expiration_time
        day=(expiration_time-now_time).days
        huor=(expiration_time-now_time).seconds//3600
        minuter=((expiration_time-now_time).seconds-3600*huor)//60
        second=((expiration_time-now_time).seconds )%60
        return  {"day":day,"huor":huor,'min':minuter,"second":second}


class Comchistory(models.Model):
    users=models.ForeignKey(to=User,related_name='numbeofvisits',on_delete=models.DO_NOTHING, db_constraint=False, verbose_name='动漫id')
    creat_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间',null=True)



